<template>
  <div class="content">图表页面</div>
  <div id="charts"></div>
</template>

<script setup lang="ts">
import { getCurrentInstance, onMounted, nextTick, ref, onUnmounted } from "vue";
import useCurrentInstance from "@/utils/useCurrentInstance";
let { proxy } = useCurrentInstance();
let myChart: any = null;

const drawChart = () => {
  myChart = proxy.$echarts.init(document.getElementById("charts"));
  myChart.setOption({
    title: {
      text: "ECharts 入门示例",
    },
    tooltip: {},
    legend: {
      data: ["销量"],
    },
    xAxis: {
      data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
    },
    yAxis: {},
    series: [
      {
        name: "销量",
        type: "bar",
        data: [5, 20, 36, 10, 10, 20],
      },
    ],
  });

  window.addEventListener("resize", () => {
    nextTick(() => {
      myChart.resize();
    });
  });
};
onMounted(() => {
  nextTick(() => {
    drawChart();
  });
});
onUnmounted(() => {
  myChart.dispose();
});
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  height: 60px;
  line-height: 60px;
  background: #ededed;
}
#charts {
  width: 100%;
  height: 400px;
}
</style>
